package com.hbue.water.controller;

import com.hbue.water.common.CommonResult;
import com.hbue.water.common.ResponseCode;
import com.hbue.water.entity.Account;
import com.hbue.water.service.AccountService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yushu
 * @date 2021/12/27
 * @apiNate
 */
@RestController
@RequestMapping("/account")
@ApiModel("处理登陆模块的请求")
@Slf4j
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("/login")
    public CommonResult login(
            @ApiParam(name="account",value="表单采集的用户登陆信息",required = true)
            @RequestBody Account account
    ) {
        // 调用登陆的业务逻辑完成登陆
        boolean result = accountService.login(account.getUserName(), account.getUserPwd());
        // 条件成立：登录成功
        if (result) {
            return new CommonResult<>(ResponseCode.RESPONSE_SUCCESS,"success");
        } else {
            return new CommonResult<>(ResponseCode.RESPONSE_FAIL,"fail");
        }
    }

    //@ApiOperation("注册管理员")
    //@PostMapping("/saveAcc")
    //public CommonResult saveAccount(
    //        @ApiParam(name = "account", value = "前端采集的管理员信息", required = true)
    //        @RequestBody Account account) {
    //    boolean flag = accountService.saveAccount(account);
    //    if (flag) {
    //        return new CommonResult(ResponseCode.RESPONSE_SUCCESS, "注册成功!");
    //    } else {
    //        return new CommonResult(ResponseCode.RESPONSE_FAIL, "注册失败，用户名已存在！");
    //    }
    //}
}
